﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Cards.Util;

namespace Cards.GUI
{
    public partial class UserInfo : Form
    {
        private String m_playerName;
        private int m_numPlayer;
        private CARD_PLAYING_KIND m_gameKind;
        private MULTI_PLAYER_TYPE m_multiType;

        public String PLAYERNAME
        {
            get { return m_playerName; }
            set
            {
                m_playerName = value;
                txtPlayerName.Text = value;
            }
        }
        public int NUMPLAYER
        {
            get { return m_numPlayer; }
            set
            {
                m_numPlayer = value;
                cbNumPlayer.SelectedValue = value.ToString();
            }
        }
        public CARD_PLAYING_KIND GAMEKIND
        {
            get { return m_gameKind; }
            set
            {
                m_gameKind = value;
                cbGameKind.SelectedIndex = (int)value;
            }
        }
        public MULTI_PLAYER_TYPE MULTITYPE
        {
            get { return m_multiType; }
            set
            {
                m_multiType = value;
                cbPlayingKind.SelectedIndex = (int)value;
                this.Validate();
            }
        }

        public UserInfo()
        {
            InitializeComponent();
        }

        private void UserInfo_Load(object sender, EventArgs e)
        {
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            m_playerName = txtPlayerName.Text;

            if (txtPlayerName.Text.Trim() == "")
            {
                DlgMsgBox dlg = new DlgMsgBox();
                dlg.MESSAGETEXT = "Vui lòng nhập tên người chơi";
                dlg.ShowDialog(this);
                txtPlayerName.Select();
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        
        private void cbPlayingKind_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbPlayingKind.SelectedIndex == (int)MULTI_PLAYER_TYPE.SINGLE_PLAYER)
            {
                m_multiType = MULTI_PLAYER_TYPE.SINGLE_PLAYER;
            }
            else if (cbPlayingKind.SelectedIndex == (int)MULTI_PLAYER_TYPE.MULTI_PLAYER_SERVER)
            {
                m_multiType = MULTI_PLAYER_TYPE.MULTI_PLAYER_SERVER;
            }
            else if (cbPlayingKind.SelectedIndex == (int)MULTI_PLAYER_TYPE.MULTI_PLAYER_CLIENT)
            {
                m_multiType = MULTI_PLAYER_TYPE.MULTI_PLAYER_CLIENT;
            }
        }

        private void cbGameKind_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = 2;

            if (cbGameKind.SelectedIndex == (int)CARD_PLAYING_KIND.VNPOCKER)
            {
                m_gameKind = CARD_PLAYING_KIND.VNPOCKER;
                
                cbNumPlayer.Items.Clear();
                for (i = 2; i <= Constants.VNPOCKER_MAX_PLAYERS; i++)
                {
                    cbNumPlayer.Items.Add(i);
                }

                cbNumPlayer.SelectedItem = i - 1;
            }
            else if (cbGameKind.SelectedIndex == (int)CARD_PLAYING_KIND.BLACKJACK)
            {
                m_gameKind = CARD_PLAYING_KIND.BLACKJACK;

                cbNumPlayer.Items.Clear();
                for (i = 2; i <= Constants.BLACKJACK_MAX_PLAYERS; i++)
                {
                    cbNumPlayer.Items.Add(i);
                }

                cbNumPlayer.SelectedItem = i - 1;
            }
            else if (cbGameKind.SelectedIndex == (int)CARD_PLAYING_KIND.CATTE)
            {
                m_gameKind = CARD_PLAYING_KIND.CATTE;
            }
        }

        private void cbNumPlayer_SelectedValueChanged(object sender, EventArgs e)
        {
            m_numPlayer = (int)cbNumPlayer.SelectedItem;
        }

        private void txtPlayerName_Leave(object sender, EventArgs e)
        {
            if (txtPlayerName.Text.Trim() == "")
            {
                DlgMsgBox dlg = new DlgMsgBox();
                dlg.MESSAGETEXT = "Vui lòng nhập tên người chơi";
                dlg.ShowDialog(this);
            }
        }
    }
}
